package eu.szemraj.geom {
	import eu.szemraj.utils.ConverterUtil;   		import flash.geom.Point;   

   public class Trigo {

      public static const PI:Number = Math.PI;

      public static function cosD(angle:Number):Number {
   	
         return Math.cos( angle * ConverterUtil.DEG_TO_RAD ) ;
      }

      public static function sinD(angle:Number):Number {
   	
         return Math.sin( angle * ConverterUtil.DEG_TO_RAD ) ;
      }

      public static function atan2D( y:Number , x:Number ):Number {
   
         return Math.atan2( y, x ) * ConverterUtil.RAD_TO_DEG ;
      }

      public static function fixAngle(angle:Number ):Number {
      	
         if ( isNaN( angle ) ) {
         	    
            angle = 0 ;
         }
         
         angle %= 360 ;
         return (angle < 0) ? angle + 360 : angle ;
      }

      public static function noramlizeAngle( radians:Number ):Number {
      	
      	
         if( radians < 0 || radians > ( PI << 1) ) return Math.abs( ( PI << 1 ) - Math.abs( radians ) );
      	else return radians;
      }

      public static function calculateAngle( p1:Point, p2:Point ):Number {
      	
         var angle:Number = Math.atan( (p2.y - p1.y) / (p2.x - p1.x) ) * ConverterUtil.RAD_TO_DEG;
 			
         if( p2.y < p1.y && p2.x > p1.x ) {
            return angle;
         }
         if( ( p2.y < p1.y && p2.x < p1.x ) || ( p2.y > p1.y && p2.x < p1.x ) ) {
            return angle + 180;
         }
         return angle + 360;       
      }
   }
}
